<style lang="scss" scoped>
	.content {
		width: 100%;
		background-color: white;
		padding: 30rpx 0;
	}

	.list {
		padding: 25rpx;
		border-bottom: 1px solid #ccc;
		align-items: flex-start;
		color: #737373;

		.red {
			transform: translateY(6rpx);
		}

		.textarea {
			width: 460rpx;
			height: 120rpx;
			font-size: 28rpx;
		}

		.mic {
			height: 120rpx;
			width: 80rpx;
			border-left: 1px solid #ccc;
			padding-left: 20rpx;
		}

		.ipt {
			width: 550rpx;
		}

		.uploadfile {
			width: 550rpx;

			.btns {
				width: 100%;

				.btn {
					width: 152rpx;
					height: 64rpx;

					border: 2rpx solid #bfbfbf;
					border-radius: 34rpx;
				}
			}
		}

		.record {
			width: 550rpx;
		}
	}

	.title {
		padding: 20rpx;
		border-bottom: 1px solid #ccc;
		;
	}
</style>

<template>
	<view class="content">
		<view class="f34 bold" style="padding:0 30rpx;border-bottom: 1px solid #ccc;padding-bottom: 20rpx;">送修
		</view>
		<scroll-view scroll-y="true" style="height: 80vh;">

			<view class="f28 bold title">设备信息</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					设备编号
				</view>
				<view class="between-flex " style="width: 550rpx;">
					<input style="width: 490rpx;" class="ipt" type="text" value="" placeholder="请输入设备编号" />
					<view style="flex:1;padding-left: 20rpx;border-left: 1px solid #ccc;">
						<u-icon name="scan" color="#409EFF" size="32"></u-icon>
					</view>
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					设备名称
				</view>
				<view class="align-flex ">
					<input class="ipt" type="text" value="" placeholder="请输入设备名称" />
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					设备分类
				</view>
				<view class="align-flex blue">请选择 <u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					设备型号
				</view>
				<view class="align-flex ">
					<input class="ipt" type="text" value="" placeholder="请输入设备型号" />
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					设备序列号
				</view>
				<view class="align-flex ">
					<input class="ipt" type="text" value="" placeholder="请输入设备序列号" />
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					数据重要性
				</view>
				<view class="align-flex blue">重要未备份 <u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					设备信息备注
				</view>
				<view class="align-flex ">
					<textarea style="width:500rpx;" class="textarea" value="" maxlength="-1" placeholder="请填写设备信息备注" />

				</view>
			</view>
			<view class="f28 bold title">故障原因</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					故障描述
				</view>
				<view class="align-flex ">
					<textarea style="width:550rpx;" class="textarea" value="" maxlength="-1" placeholder="请填写	故障描述" />

				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					备注
				</view>
				<view class="align-flex ">
					<textarea style="width:550rpx;" class="textarea" value="" maxlength="-1" placeholder="请填写备注" />

				</view>
			</view>
			<view class="f28 bold title">其他信息</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					科室名称
				</view>
				<view class="align-flex blue" @click="$go(PagesCourseRouterConfig.DeptId)">
					{{deptId?deptId.name:'请选择'}}
					<u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					科室联系人
				</view>
				<picker mode="selector" :range="users" range-key="name" @change="choose($event,3,users)">
					<view class="align-flex blue">
						{{user?user.name:'请选择'}}
						<u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
					</view>
				</picker>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					科室电话
				</view>
				<view class="align-flex ">
					<input class="ipt" type="text" value="" placeholder="请输入" />
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					科室地点
				</view>
				<view class="align-flex ">
					<input class="ipt" type="text" value="" placeholder="请输入" />
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					送修时间
				</view>
				<view class="align-flex blue" @click="show=true">{{date?date:'请选择'}}
					<u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					送修方式
				</view>
				<view class="align-flex blue">请选择 <u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					第三方公司
				</view>
				<view class="align-flex blue">请选择 <u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					附件
				</view>
				<view class="uploadfile">
					<view class="btns align-flex m-bottom20">
						<view class="btn center-flex c666 " @click="uploadfile" style="margin-right: 40rpx;">上传</view>
						<view class="btn center-flex bgblue cfff" @click="chooseImg">拍照</view>
					</view>
					<view class="p-top10 between-flex" v-for="item,index in enclosure" :key="index">
						<view class="align-flex blue" @click="$open(item.url)">
							<u-icon name="file-text" color="#409EFF" size="38"></u-icon>
							{{item.fileName.substring(item.fileName.length-10)}}
						</view>
						<u-icon @click="delfile(index)" name="close" color="#666666" size="30"></u-icon>
					</view>
				</view>
			</view>

			<view class="lbtn">送修</view>
		</scroll-view>
		<u-picker v-model="show" :params="params" mode="time" @confirm="chooseDate"></u-picker>
	</view>
</template>

<script>
	import PagesCourseRouterConfig from '@/pagesCourse/routerConfig.js'
	export default {
		props: {
			orderNum: {
				default: ''
			}
		},
		data() {
			return {
				PagesCourseRouterConfig,
				show: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				date: '',
				head: this.$head,
				users: [],
				user: null,
				deptId: null, //报修科室
				multiSelector: [

				],
				enclosure: [], //附件
			}
		},
		created() {
			uni.$on('choosedept', (data) => {
				console.log(data)
				this.deptId = data
			})
			var users = uni.getStorageSync('user')
			for (var key in users) {
				this.users.push({
					name: users[key],
					value: key,
					content: ''
				})
			}

		},
		beforeDestroy() {
			uni.$off('choosedept')
		},
		methods: {
			delfile(index) {
				this.enclosure.splice(index, 1)
			},
			chooseDate(e) {
				console.log(e)

				this.date = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`


			},
			choose(e, type, list) {

				switch (type) {
					case 1:
						this.reason = list[e.detail.value];
						break;
					case 2:
						console.log(list)
						var index = e.detail.value
						if (list[2].length != 0) {
							this.deptId = list[2][e.detail.value[2]]
						} else if (list[1].length != 0) {
							this.deptId = list[1][e.detail.value[1]]
						} else if (list[0].length != 0) {
							this.deptId = list[0][e.detail.value[0]]
						}
						console.log(this.deptId)
						break;
					case 3:
						this.user = list[e.detail.value];
						break;
					case 4:
						this.degree = list[e.detail.value];
						break;
					case 5:
						this.system = list[e.detail.value];
						break;

				}

			},

			//选择图片
			async chooseImg() {

				var file = await this.$chooseImg()

				this.enclosure.push(file)

			},
			async uploadfile() {

				var file = await this.$uploadfile()
				this.enclosure.push(file)

			},
			submit() {
				if (!this.reason) {
					this.$msg('请选择暂停原因')
					return
				}

				uni.showLoading({
					title: '提交中...'
				})
				var obj = {
					orderNum: this.orderNum,
					remark: this.remark,
					processValue: this.reason.value
				}
				if (this.enclosure.length > 0) {
					var enclosure = []
					this.enclosure.forEach(item => {
						enclosure.push({
							name: item.oldName,
							url: item.url
						})
					})
					obj['processEnclosure'] = JSON.stringify(enclosure)
				}
				return
				this.$pop.ajaxPost('/wechat/order/suspend', obj).then(res => {
					uni.hideLoading()
					if (res.code == 0) {
						this.$msg('提交成功')
						this.$emit('submit')
					}
				})
			},


		}
	}
</script>
